'use strict';

/**
 * @description 房屋信息表模型
 * */
module.exports = app => {
  const { STRING, INTEGER, TEXT } = app.Sequelize;

  const HouseInfo = app.model.define('houseInfo', {
    content: {
      type: TEXT,
      allowNull: true,
      comment: '介绍',
    },
    pictures: {
      type: TEXT,
      allowNull: true,
      comment: '相关图片',
    },
    houseArea: {
      type: INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: '房屋面积',
    },
    direction: {
      type: STRING(10),
      allowNull: true,
      comment: '房子朝向',
    },
    floor: {
      type: STRING(20),
      allowNull: true,
      comment: '楼层',
    },
    type: {
      type: STRING(20),
      allowNull: true,
      comment: '房型',
    },
    remarks: {
      type: TEXT,
      allowNull: true,
      comment: '备注',
    },
    personNum: {
      type: INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: '宜居人数',
    },
    deviceIds: {
      type: STRING(100),
      allowNull: true,
      comment: '设备的ids',
    },
    advantageIds: {
      type: STRING(100),
      allowNull: true,
      comment: '特点的ids',
    },
    houseId: {
      type: INTEGER,
      allowNull: false,
      comment: '房屋id',
    },
    status: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: '状态 1-暂存 2-待审核 3-同意 4-拒绝',
    },
  });

  HouseInfo.associate = () => {
    app.model.HouseInfo.belongsTo(app.model.House, {
      foreignKey: 'houseId',
    });
  };

  return HouseInfo;
};
